Vue.filter("date2datetime",function (value,format){
	return dateFormat(value,format);
});
Vue.filter("timestamp2datetime",function (value,format){
	return timestampFormat(value,format);
});


var vm  = T.vm = new Vue({
	el:'#webpage',
	data:{
		appearance : {
			showList: true,
			showControllBar : true,
			showSearchForm : true
		},
		q:{
			_keyword:''
		},
		title: null,
		records: {
			filter:{
				page: 1,
				limit: 12,
			},
			list : [],
			currPage: 1,
			total: 0,
			pageSize: 12,
			totalPage : 0
		}
	},
	mounted : function(){

		this.getdata();
	},

	methods: {
		getdata : function(){
			var that = this;
			this.records.filter.page = this.records.currPage;
			this.records.filter.limit = this.records.pageSize;
			var where = jQuery.param(this.records.filter);
			var url = str_format('{0}dataview/viewliveroomlist/query_data_list?{1}',baseURL,where);
			console.log(url)
			T.loading(true)
			apiget(url).then(function (res) {
				T.loading(false)
				var data = res.page;
				console.log(data);
				that.records.list = data.list;
				that.records.currPage = data.currPage;
				that.records.pageSize = data.pageSize;
				that.records.total = data.totalCount;
				that.records.totalPage = data.totalPage;

			})
		},
		reload : function (){

		},
		query: function () {

		},
		selectPage : function (page){
			console.log(str_format("当前选择第 {0} 页",page))
			this.records.currPage = page;
			this.getdata();
		},
		forbidden : function (row){
			var state = -1;
			var uid = row.uid;
			console.log(row)
			var dialog = layer.open({
				type: 1,
				area: ['500px', 'auto'],
				title: '禁止直播',
				shade: 0.6,
				anim: 1,
				shadeClose : !0,
				content:'<form class="set-room-state-form">' +
					'<div style="padding:10px  30px;">' +
					'<div style="padding: 10px 0px; line-height: 180%;"><font color="red">如果主播当前正在直播则中断直播，并且禁止以后其开启直播推流，主播可以重新开始直播，请谨慎做此操作 !</font></div>' +
					'<div class="form-group">' +
					'<p>' +
					'<textarea style="width: 100%; height:100px; line-height: 180%; padding: 10px; border:solid 1px #dbdbdb; outline: none;">您的直播室由于相关原因被禁止直播，若有疑问，请联系客服人员 !</textarea>' +
					'</p>' +
					'</div>' +
					'<div class="form-group">' +
					'<p><button type="button" class="btn btn-danger ok">确认信息并提交</button></p>' +
					'</div>' +
					'</div></form>',
				success : function (index){
					var form = $('.set-room-state-form');
					form.on('click','button.btn.ok',function (){
						var text = form.find('textarea:first').val();
						apipost('live/liveroom/set_room_state',{
							uid : uid,
							state : state,
							remark : text
						}).then(function (res) {
							if(res.code>0){
								$("#jqGrid").trigger('reloadGrid');
								alert('操作成功');
							}
							else{
								alert(res.msg);
							}
						});
						parent.layer.closeAll();
					})
				}
			});
		},
		preview : function (row) {
			T.loading(true)
			var url = str_format('{0}live/liveroom/get_live_play_url?uid={1}',baseURL,row.uid);
			var img = $(str_format('#IMG_PREVIEW_{0}',row.uid));
			var containerId = '#live_video_player';
			console.log(img.height());
			$(containerId).css({
				width : img.width(),
				hieght : img.height() + 80
			})

			console.log([img.width(),img.height()]);
			apiget(url).then(function (res){
				T.loading(false)
				if(res.code>0){
					layer.open({
						type: 1,
						title : false,
						skin: 'previewVideoDialog', //样式类名
						closeBtn:1, //不显示关闭按钮
						area: [img.width() + "px",img.height() + "px"],
						shadeClose: true, //开启遮罩关闭
						content: $('#tpl_live_player').html(),
						success:function (){
							$('#video').css({
								height: img.height()
							})
							var player = new TcPlayer('video', {
								"m3u8":res.data.HLS,
								"flv": res.data.FLV, //请替换成实际可用的播放地址
								"autoplay" : true,      //iOS下safari浏览器，以及大部分移动端浏览器是不开放视频自动播放这个能力的
								"poster" : img.src,
								"width" :  img.width(),//视频的显示宽度，请尽量使用视频分辨率宽度
								"height" : img.height(),//视频的显示高度，请尽量使用视频分辨率高度
								"h5_flv":true,
								"live":true
							});
						}
					});
					console.log(res);
				}
			})
		}
	}
});